-
Notifications
You must be signed in to change notification settings - Fork 67
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add preferNative
option
#77
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
3ecfe9b
to
0a2aa8b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add the same option to Provider
as well? And adjust the provider to pass it down. Thanks!
aa2e98f
to
aa552c0
Compare
src/index.tsx
Outdated
@@ -176,24 +191,25 @@ const Balancer = <ElementType extends React.ElementType = React.ElementType>({ | |||
}: BalancerProps<ElementType>) => { | |||
const id = useId() | |||
const wrapperRef = React.useRef<WrapperElement>() | |||
const hasProvider = React.useContext(BalancerContext) | |||
const contextValue = React.useContext(BalancerContext) | |||
const preferNativeBalancing = preferNative && contextValue.preferNative |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @shuding,
Should Balancer
be able to override the preferNative
context value when the provider passes false
? It seems to me overriding the true
value from context is more likely to happen, as the case mentioned in #75 🤔 So, it only allows overriding preferNative: true
for now. What are your thoughts on this? Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes I think it should be able to override. Maybe we can extend this context to be an array or an object to contain more information if necessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated Balancer
in b9ceaa1.
If preferNative
is not provided to Balancer
, the ??
operator will take the value from the context, which defaults to true
in createContext
and in Provider
. So when preferNative
is explicitly provided, it can override.
@@ -184,7 +184,7 @@ const Provider: React.FC<{
const Balancer = <ElementType extends React.ElementType = React.ElementType>({
ratio = 1,
- preferNative = true,
+ preferNative,
nonce,
children,
...props
@@ -192,7 +192,7 @@ const Balancer = <ElementType extends React.ElementType = React.ElementType>({
const id = useId()
const wrapperRef = React.useRef<WrapperElement>()
const contextValue = React.useContext(BalancerContext)
- const preferNativeBalancing = preferNative && contextValue.preferNative
+ const preferNativeBalancing = preferNative ?? contextValue.preferNative
const Wrapper: React.ElementType = props.as || 'span'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
Provide an option to opt out of the native CSS text-balancing when the
text-wrap: balance
can't serve the needs or a customized ratio is preferred.Closes #75.